<template>
<div class="contain">
  <div class="loader-base" v-if="showLoad"><div class="loader-wrap"></div></div>
  <div class="address-list" v-for="item in todolist" @click="checkAddress(item)">
    <dl>
     <dd class="ft14">{{item.Province | province}}{{item.City | city}}{{item.District | district}}{{item.Address}} </dd>
    </dl>
    <div class="addr-foot cf">
      <div class="f-r">
        <span class="mr20" @click.stop="EditAddress(item.Guid)"><i class="iconfont icon-order-entry"></i>编辑</span>
        <span @click.stop="DelAddress(item.Guid)"><i class="iconfont icon-delete2"></i>删除</span>
      </div>
    </div>
  </div>
  <div class="noDate_page" v-if="todolist.length<=0">
    <div class="noDate_icon"><i class="iconfont icon-null"></i></div>
    未找到相关数据
  </div>
  <div @click="add" class="btn-bottom"><div class="btn">新增</div></div>
</div>
</template>

<script>
export default {
  name:'transaddressList',
  data() {
    return {
      todolist: [],
      showLoad: false,
    };
  },
  computed:{
    userinfo() {
      if (localStorage.UserInfo) {
        return JSON.parse(localStorage.UserInfo);
      }
    },
  },
  created(){
    this.getData();
  },
  methods:{
    checkAddress(item){
      var self= this;
      this.showLoad = true;
      sessionStorage.ZZAddress =''
      sessionStorage.ZZAddress = JSON.stringify(item);

      var query = {
        Guid: item.Guid,
        type: item.type,
        LoginedStaffID: this.userinfo.StaffID,
        LoginedName: this.userinfo.Name
      };
      this.Ajax.post("SetDefaultCustomerAddress", query).then(function(resp) {
        self.showLoad = false;
        if (resp.IsSuccess) {
          self.$router.push({
            path: "/onlineOrder",
            query:{
              id: self.$route.query.id,
              Billtype:self.$route.query.Billtype,
            }
          });
        } else {
          self.$vux.toast({
            type:'warn',
            text:resp.ErrorMessage,  
          });
        }
      });
    },
    EditAddress(id){
      this.$router.push({
        path: "/transaddressForm",
        query:{ 
          AddressGuid: id,
          id: this.$route.query.id,
          Billtype:this.$route.query.Billtype,
        }
      });
    },
    DelAddress(id){
      var self = this;
      this.$vux.confirm.show({
        title:'提示',
        content: '确认删除客运站信息吗',
        onConfirm () {
          if(sessionStorage.ZZAddress != '' && sessionStorage.ZZAddress != null)
          {
            var InSessionAddress = JSON.parse(sessionStorage.ZZAddress).Guid;
            if(InSessionAddress == id) {
              sessionStorage.removeItem('ZZAddress');
            }
          }
          var query = {
            Guid: id
          };
          self.showLoad = true;
          self.Ajax.post("DelCustomerAddress", query).then(function(resp) {
            if (resp.IsSuccess) {
              self.$vux.toast.show({
                type: "success", //success, warn, cancel, text
                text: "删除成功"
              });
              self.getData();
              self.showLoad = false;
            }
          });
        }
      });
    },
    add(){
      var query = this.$route.query;
      query.type=this.types;
      this.$router.push({
        path: "/transaddressForm",
         query: query
      });
    },
    getData(){
      var self = this;
      var query = {
        CreateUserId: this.userinfo.StaffID,
        type: 3,
        PageIndex:1,
        PageSize:100
      };
      self.showLoad = true;
      this.Ajax.post("SearchCustomerAddress", query).then(function(resp) {
        self.showLoad = false;
        self.todolist = resp.Datas;
      });
    },
  }
}
</script>